/**
 * Sample Skeleton for 'FactoryPatternUI.fxml' Controller Class
 */

package cn.edu.scau.cmi.youbaiquan.controller;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.youbaiquan.domain.Insurance;
import cn.edu.scau.cmi.youbaiquan.factory.AccidentsInsuranceFactory;
import cn.edu.scau.cmi.youbaiquan.factory.BodyInjuryInsuranceFactory;
import cn.edu.scau.cmi.youbaiquan.factory.CarDamageInsuranceFactory;
import cn.edu.scau.cmi.youbaiquan.factory.CasualtiesInsuranceFactory;
import cn.edu.scau.cmi.youbaiquan.factory.InsuranceFactory;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;

public class FactoryPatternController {

    @FXML // ResourceBundle that was given to the FXMLLoader
    private ResourceBundle resources;

    @FXML // URL location of the FXML file that was given to the FXMLLoader
    private URL location;

    @FXML // fx:id="choice_box"
    private ChoiceBox<String> choice_box; // Value injected by FXMLLoader

    @FXML // fx:id="btn_showinsurance"
    private Button btn_showinsurance; // Value injected by FXMLLoader

    @FXML // fx:id="tv_result"
    private TextArea tv_result; // Value injected by FXMLLoader

    @FXML
    void displayMessage() {
        String str = choice_box.getValue();
        InsuranceFactory insuranceFactory = null;
        switch (str) {
            case "身体受伤":
                insuranceFactory = new BodyInjuryInsuranceFactory();
                break;
            case "汽车损坏":
                insuranceFactory = new CarDamageInsuranceFactory();
                break;
            case "人员伤亡":
                insuranceFactory = new CasualtiesInsuranceFactory();
                break;
            case "多种事故":
                insuranceFactory = new AccidentsInsuranceFactory();
                break;
        }
        if (insuranceFactory != null) {
            Insurance insurance = insuranceFactory.getInstance();
            tv_result.setText(insurance.showInsurance());
        }
    }

    @FXML // This method is called by the FXMLLoader when initialization is complete
    void initialize() {
        assert choice_box != null : "fx:id=\"choice_box\" was not injected: check your FXML file 'FactoryPatternUI.fxml'.";
        assert btn_showinsurance != null : "fx:id=\"btn_showinsurance\" was not injected: check your FXML file 'FactoryPatternUI.fxml'.";
        assert tv_result != null : "fx:id=\"tv_result\" was not injected: check your FXML file 'FactoryPatternUI.fxml'.";
        
        ObservableList<String> options = FXCollections.observableArrayList("身体受伤", "汽车损坏", "人员伤亡", "多种事故");
        choice_box.setValue("身体受伤");
        choice_box.setItems(options);
    }
    
}
